
<%@ include file="/commons/global.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>家庭表</title>
</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">
	<div data-options="region:'west',split:true,border:false,title:'菜单列表'"	>
   <div id="tb" style="padding: 5px; ">
			<div>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-add" plain="true" onclick="add();">添加</a> <span
					class="toolbar-item dialog-tool-separator"></span> 
			</div>
		</div>
		<table id="dg"></table>
	</div>
	<div
		data-options="region:'center',split:true,border:false,title:'家庭成员列表'">
		<div id="familyInfoTb" >
			<div>
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="infoAdd();">添加</a> 
					<span class="toolbar-item dialog-tool-separator"></span> 
			</div>
		</div>
		<table id="familyInfoDg"></table>
	</div>
	<div id="dlg"></div>
	<script type="text/javascript">
		var dg;
		var familyInfoDg;
		var d;
		$(function() {
			dg = $('#dg').datagrid(
					{
						url : '${path}/family/dataGrid',
						striped : true,
						rownumbers : true,
						pagination : true,
						singleSelect : true,
						idField : 'id',
						sortName : 'id',
						sortOrder : 'asc',
						pageSize : 20,
						pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400,
								500 ],
						columns : [ [ {
							field : 'id',
							title : '编号',
							width : 100
						}, {
							field : 'familyNo',
							title : '家庭编号',
							width : 150
						}, {
							field : 'housemaster',
							title : '户主名称',
							width : 150
						}, {
							field : 'cardNo',
							title : '身份证号',
							width : 150
						}, {
							field : 'areaNo',
							title : '所在村编号',
							width : 100
						}, {
							field : 'createDate',
							title : '建档时间',
							width : 100
						},
						{
							field : 'action',
							title : '操作',
							width : 200,
							formatter : function(value, row, index) {
								var str = '';
								<shiro:hasPermission name="/family/edit">
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="family-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="familyEditFun(\'{0}\');" >编辑</a>',
												row.id);
								</shiro:hasPermission>
								<shiro:hasPermission name="/family/delete">
								str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="family-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="familyDeleteFun(\'{0}\');" >删除</a>',
												row.id);
								</shiro:hasPermission>
								return str;
							}
						}
						] ],
						headerContextMenu : [
								{
									text : "冻结该列",
									disabled : function(e, field) {
										return dg.datagrid("getColumnFields",
												true).contains(field);
									},
									handler : function(e, field) {
										dg.datagrid("freezeColumn", field);
									}
								},
								{
									text : "取消冻结该列",
									disabled : function(e, field) {
										return dg.datagrid("getColumnFields",
												false).contains(field);
									},
									handler : function(e, field) {
										dg.datagrid("unfreezeColumn", field);
									}
								} ],
						enableHeaderClickMenu : true,
						enableHeaderContextMenu : true,
						enableRowContextMenu : false,
						toolbar : '#tb',
						onClickRow : function(rowIndex, rowData) {
							var familyNo = rowData.familyNo;
							//alert(familyNo);
							familyInfoDg = $('#familyInfoDg');
							familyInfoDg.datagrid({
								url : '${path}/familyInfo/dataGrid?familyNo=' + familyNo
							});
							familyInfoDg.datagrid('reload', {
								filter_EQS_familyNo : familyNo
							})
						}
					});
		});

		//弹窗增加
		function add() {
			d = $("#dlg").dialog({
				title : '添加家庭表',
				width : 700,
				height : 600,
				href : '${path}/family/addPage',
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#familyAddForm").submit();
					}
				} ]
			});
		}

		/**
		 * 删除
		 */
		function familyDeleteFun(id) {
			//alert(id);
			parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
				if (b) {
					progressLoad();
					$.post('${path}/family/delete', {
						id : id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							//familyDataGrid.datagrid('reload');
						}
						progressClose();
					}, 'JSON');
				}
			});
		}
		
		/**
		 * 编辑家庭
		 */
		function familyEditFun(id) {
			parent.$.modalDialog({
				title : '编辑',
				width : 700,
				height : 600,
				href : '${path}/family/editPage?id=' + id,
				buttons : [ {
					text : '确定',
					handler : function() {
						//parent.$.modalDialog.openner_dataGrid = familyDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler
								.find('#familyEditForm');
						f.submit();
					}
				} ]
			});
		}

		//查看
		function look() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '查看家庭表',
				width : 380,
				height : 340,
				href : '${path}/family/manager',
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}

		//创建查询对象并查询
		function cx() {
			var obj = $("#searchFrom").serializeObject();
			dg.datagrid('load', obj);
		}
		//时间格式化
		function dateFormatter(value) {
			var date = new Date(value);
			return dateFtt('yyyy-MM-dd hh:mm:ss', date);
		}

		$(function() {
			familyInfoDg = $('#familyInfoDg').datagrid(
					{

						url : '${path}/familyInfo/dataGrid',
						striped : true,
						rownumbers : true,
						pagination : true,
						singleSelect : true,
						idField : 'id',
						sortName : 'id',
						sortOrder : 'asc',
						pageSize : 20,
						pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400,
								500 ],
						columns : [ [ {
							field : 'id',
							title : '编号',
							width : 100
						}, {
							field : 'familyInfoNo',
							title : '成员编号',
							width : 150
						}, {
							field : 'familyNo',
							title : '家庭编号',
							width : 150
						}, {
							field : 'cardNo',
							title : '身份证号',
							width : 150
						}, {
							field : 'name',
							title : '姓名',
							width : 100
						}, {
							field : 'gender',
							title : '性別',
							width : 100
						}, {
							field : 'age',
							title : '年齡',
							width : 100
						}, {
							field : 'address',
							title : '家庭住址',
							width : 100
						}, {
							field : 'contact',
							title : '联系方式',
							width : 100
						}, {
							field : 'relaType',
							title : '与户主关系',
							width : 100
						} ,
						{
							field : 'action',
							title : '操作',
							width : 200,
							formatter : function(value, row, index) {
								var str = '';
								<shiro:hasPermission name="/familyInfo/edit">
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="family-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="familyInfoEditFun(\'{0}\');" >编辑</a>',
												row.id);
								</shiro:hasPermission>
								<shiro:hasPermission name="/familyInfo/delete">
								str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="family-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="familyInfoDeleteFun(\'{0}\');" >删除</a>',
												row.id);
								</shiro:hasPermission>
								return str;
							}
						}
						
						] ],
						headerContextMenu : [
								{
									text : "冻结该列",
									disabled : function(e, field) {
										return familyInfoDg.datagrid(
												"getColumnFields", true)
												.contains(field);
									},
									handler : function(e, field) {
										familyInfoDg.datagrid("freezeColumn",
												field);
									}
								},
								{
									text : "取消冻结该列",
									disabled : function(e, field) {
										return familyInfoDg.datagrid(
												"getColumnFields", false)
												.contains(field);
									},
									handler : function(e, field) {
										familyInfoDg.datagrid("unfreezeColumn",
												field);
									}
								} ],
						enableHeaderClickMenu : true,
						enableHeaderContextMenu : true,
						enableRowContextMenu : false,
						toolbar : '#familyInfoTb'
					});
		});

		//弹窗增加
		function infoAdd() {
			var row = dg.datagrid('getSelected');
			alert(row.familyNo);
			d = $("#dlg").dialog({
				title : '添加家庭成员',
				width : 700,
				height : 600,
				href : '${path}/familyInfo/addPage?familyNo='+row.familyNo,
				//href : '${path}/familyInfo/addPage?familyNo='+row.familyNo,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#familyInfoAddForm").submit();
						familyInfoDg.reload();
					}
				} ]
			});
		}

		/**
		 * 删除
		 */
		function familyInfoDeleteFun(id) {
			//alert(id);
			parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
				if (b) {
					progressLoad();
					$.post('${path}/familyInfo/delete', {
						id : id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							//familyDataGrid.datagrid('reload');
						}
						progressClose();
					}, 'JSON');
				}
			});
		}

		

		//查看
		function infoLook() {
			var row = familyInfoDg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '查看',
				width : 380,
				height : 340,
				//    href:'${ctx}/exp/familyInfo/'+row.familyInfoNo,
				href : '${path}/familyInfo/mananger'+row.familyInfoNo,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}
		
		/**
		 * 编辑家庭
		 */
		function familyInfoEditFun(id) {
			parent.$.modalDialog({
				title : '编辑',
				width : 700,
				height : 600,
				href : '${path}/familyInfo/editPage?id=' + id,
				buttons : [ {
					text : '确定',
					handler : function() {
						//parent.$.modalDialog.openner_dataGrid = familyDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler
								.find('#familyInfoEditForm');
						f.submit();
					}
				} ]
			});
		}
		
		
	</script>
</body>
</html>